//
// Created by francklinson on 2021/12/31 AT 10:16.
//
#include <iostream>
#include <vector>
#include <unordered_map>
#include <queue>
#include <algorithm>
#include <functional>

using namespace std;

class Solution {
public:
    string reversePrefix(string word, char ch) {
        int pos = -1;
        for (int i = 0; i < word.size(); ++i) {
            if (word[i] == ch) {
                pos = i;
                break;
            }
        }
        if (pos == -1) {
            return word;
        } else {
            string ans;
            ans = word.substr(0, pos + 1);
            reverse(ans.begin(), ans.end());
            ans += word.substr(pos + 1);
            return ans;
        }
    }
};

int main() {
    Solution solution;
    cout << solution.reversePrefix("abcdefd", 'd') << endl;
    cout << solution.reversePrefix("xyxzxe", 'z') << endl;
    cout << solution.reversePrefix("abcd", 'z') << endl;

    return 0;
}

